<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>
<body>
  <script>
    // 记得 new Set之后加分号
    const s = new Set();
    [2, 2, 2, 2, 3, 4, 5].forEach(item => s.add(item))
    console.log(s, 's');

    for (let i of s) {
      // 值不会出现重复
      console.log(i, 'i'); // 2 3 4 5
    }

    // set可以接受一个数组用来初始化
    const s2 = new Set([1,1,1,2,2,2,3,4,5])
    console.log(s2, 's2'); // {1,2,3,4,5}
    console.log(s2.size, 's2.size'); // 5

    // 去除数组里面的重复成员
    console.log([...new Set([1,1,1,2,2,2,3,3,3,])]); // [1,2,3]
    // 去除重复的字符串
    console.log([...new Set('abbc')].join('')); // abc
    // 向set里面添加值时不会进行类型转换
    let a = NaN
    let b = NaN
    console.log([...new Set(['5', 5, a, b])]); // 算法类似=== 是精确相等

    // 两个对象总是不相等的
    let c = {}
    let d = {}
    // 两个对象
    console.log([...new Set([c, d])]); 
  </script>
</body>
</html>